package com.qf.java2207.no3_teamproject_springboot_01.service.impl;
//须知少时凌云志，曾许人间第一流

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
;
import com.qf.java2207.no3_teamproject_springboot_01.mapper.SecurityManagementMapper;
import com.qf.java2207.no3_teamproject_springboot_01.pojo.SecurityManagement;
import com.qf.java2207.no3_teamproject_springboot_01.service.SecurityManagementService;
import com.qf.java2207.no3_teamproject_springboot_01.vo.LayuiPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SecurityManagementServiceImpl implements SecurityManagementService {
    @Autowired

    private SecurityManagementMapper securityManagementMapper;


    @Override
    public LayuiPageVo<SecurityManagement> securityManagementPageData(Map<String, Object> params) {
        // mybatis 的 分页插件
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params.get("limit")+"");
        PageHelper.startPage(page,limit);

        List<SecurityManagement> securityManagements = securityManagementMapper.selectByParams(params);

        // mybatis 的 分页数据结构
        PageInfo<SecurityManagement> securityManagementPageInfo = new PageInfo<>(securityManagements);
        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中

        LayuiPageVo<SecurityManagement> securityManagementLayuiPageVo = new LayuiPageVo<>();
        securityManagementLayuiPageVo.setCode(0);  // layui 默认 0 是正确的状态码
        securityManagementLayuiPageVo.setMsg("分页列表数据"); // 提示信息
        securityManagementLayuiPageVo.setCount(securityManagementPageInfo.getTotal()); // 总记录数
        securityManagementLayuiPageVo.setData(securityManagementPageInfo.getList());  // 分页的列表数据
        return securityManagementLayuiPageVo;
    }

//    @Override
//    public List<SecurityManagement> securityManagementsList() {
//        return securityManagementMapper.selectByExample(null);
//    }


    @Override
    public int deleteSecurityManagement(Integer id) {
        return securityManagementMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateSecurityManagement(SecurityManagement securityManagement) {

        int i = securityManagementMapper.updateByPrimaryKeySelective(securityManagement);

        return i;
    }

    @Override
    public int addSecurityManagement(SecurityManagement securityManagement) {
        int i = securityManagementMapper.insertSelective(securityManagement);
        return i;
    }

}
